package com.xt.service.impl;

import com.xt.bean.StudentAttendance;
import com.xt.dao.StudentAttendanceRepository;
import com.xt.dto.StudentAttendanceListSearchDto;
import com.xt.service.StudentAttendanceService;
import com.xt.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * Created by XT on 2018/5/3.
 */
@Service
public class StudentAttendanceServiceImpl implements StudentAttendanceService {

    @Autowired
    StudentAttendanceRepository sar;
    

    @Override
    public void saveOrUpdateOne(StudentAttendance d) {

        if (StringUtils.isEmpty(d.getId())) {
            //新增
            d.setCreateDate(new Date());
        }

        d.setUpdateDate(new Date());
        sar.save(d);
    }

    @Override
    public void deleteOne(String id) {
        //删除关联关系

        sar.delete(id);
    }

    @Override
    public StudentAttendance getById(String id) {
        return sar.findOne(id);
    }

    @Override
    public Page<StudentAttendance> getPage(StudentAttendanceListSearchDto dto) {

        Page<StudentAttendance> studentAttendancePage = sar.findByStudentIdLikeAndCourseIdLikeAndTeacherIdLikeAndClassIdLikeAndStudentSchoolNumberLikeAndStudentNameLike(
                dto.getStudentId(),
                dto.getCourseId(),
                dto.getTeacherId(),
                dto.getClassId(),
                dto.getStudentSchoolNumber(),
                dto.getStudentName(),
                PageUtil.getPageable(dto.getCount(),dto.getPageNo(),dto.getSortDirection(),dto.getSortField()));

        return studentAttendancePage;
    }




}
